import React, { Component } from 'react'
import { Form, Input } from 'antd'
import PropTypes from 'prop-types'

class UpdateForm extends Component {
  static propTypes = {
    currentRowData: PropTypes.object.isRequired,
    setForm: PropTypes.func.isRequired
  }

  componentDidMount() {
    //子传父 通过事件  使得父组件可以操作form
    this.props.setForm(this.props.form)
  }

  render() {
    const { getFieldDecorator } = this.props.form
    const { name: categoryName } = this.props.currentRowData
    return (
      <Form>
        <Form.Item>
          {getFieldDecorator('categoryName', {
            rules: [{ required: true, message: '请输入分类名称' }],
            initialValue: categoryName
          })(<Input placeholder="输入分类" />)}
        </Form.Item>
      </Form>
    )
  }
}

export default Form.create()(UpdateForm)
